﻿@model QDT.Core.Members.User
@{
    ViewBag.Title = "找回安全密码";
}

<script type="text/javascript" src="@Url.Content("~/Content/Default/JS/jquery.validate.js")"> </script>
<script type="text/javascript" src="@Url.Content("~/Content/Default/JS/messages_zh.js")"> </script>
<script type="text/javascript">
    $().ready(function() {
        $('form').validate({
            rules: {
                SafePassword: {
                    required: true,
                    minlength: 6
                },
                SafeConfirmPassword: {
                    required: true,
                    equalTo: "#SafePassword"
                }
            },
            messages: {
                SafePassword: {
                    required: "<br/>请输入安全密码！",
                    minlength: "<br/>请输入6位以上密码！"
                },
                SafeConfirmPassword: {
                    required: "<br/>请再次安全密码！",
                    equalTo: "<br/>两次密码不相同！"
                }
            }
        });
    });
</script>
<div class="ui-body">
    <div class="ui-inner">
        <div class="ui-grid-row">

            @Html.Action("UserMenu", new {
                                             route = MenuRoute.SafeCenter
                                         })

            <div class="ui-grid-20">
                <div class="ui-box">
                    <div class="ui-box-hd">
                        <h1 class="ui-box-title">找回安全密码</h1>
                    </div>

                    <form class="ui-form" name="" method="post" action="@Url.Action("ForgetSafePwd")">
                        <fieldset>
                            <legend>找回安全密码</legend>
                                
                            <div class="ui-form-item">
                                <label for="" class="ui-label"><span class="ui-form-required">*</span>新安全密码</label>
                                <input class="ui-input ui-input-large" type="password"  id="SafePassword" name="SafePassword"  />
                            </div>
                            <div class="ui-form-item">
                                <label for="" class="ui-label"><span class="ui-form-required">*</span>确认密码</label>
                                <input class="ui-input ui-input-large" type="password"  id="SafeConfirmPassword" name="SafeConfirmPassword"  />
                            </div>

                            <div class="ui-form-item">
                                <input type="hidden" name="Mobile" id="Mobile" value="@Model.Mobile"/>
                                <label class="ui-label" for="validCode">验证码：</label>
                                <input name="validCode" id="validCode" class="ui-input ui-input-large" style="margin-right: 5px; width: 80px;" />
                                <button type="button" id="sendValicode" style="color: #000;width: auto;" class="ui-button ui-button-gray big">获取验证码</button>
                                <p class="ui-form-explain">系统将向您绑定的手机号发送验证码短信</p>
                                <p id="validate-error"class="ui-form-explain ui-tiptext ui-tiptext-error"></p>
                            </div>
                            <div class="ui-form-item">
                                <input type="submit" class="ui-button ui-button-orange big" value="确定"/>
                                <a href="@Url.Action("SafeCenter")" class="ui-button ui-button-gray big">返回</a>
                            </div>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    $('#sendValicode').click(function() {
        var phone = $('#Mobile').val();
        var preg = /^1[3-9][0-9]\d{8}$/;
        if (!preg.test(phone)) {
            alert("请输入正确的手机号码！");
            return;
        }
        $.ajax({
            type: "post", //使用get方法访问后台
            dataType: "json", //返回json格式的数据
            url: "@Url.Action("SendSafeByPhone")", //要访问的后台地址
            data: "phone=" + phone,
            success: sendResult
        });
    });

    var wait = 90;

    function sendResult(result) {
        if (result.Status) {
            sendSuccess();
        } else {
            alert(result.Info);
        }
    }

    function sendSuccess() {
        if (wait == 0) {
            $('#sendValicode').removeAttr("disabled").attr('style', 'color:#000;width:auto;');
            $('#sendValicode').text('获取验证码');
            wait = 90;
            return;
        } else {
            $('#sendValicode').attr('disabled', 'disabled').attr('style', 'color:#999;width:auto;');
            $('#sendValicode').text('再次获取(' + wait + ')');
            wait = wait - 1;
            setTimeout(function() {
                sendSuccess();
            },
                1000);
        }
    }

</script>